"""
任务进度追踪工具
提供进度更新和通知功能
"""

import asyncio
from loguru import logger
from typing import Optional
from .progress_tracker import ProgressTracker


class ProgressContext:
    """进度上下文管理器 - 简化版，代理到ProgressTracker"""

    def __init__(self, task_id: str = "", task_name: str = ""):
        """初始化进度上下文"""
        self.tracker = ProgressTracker(task_id, task_name)

    async def start(self, total_steps: int = 100, message: str = "任务开始..."):
        """开始任务"""
        await self.tracker.start(total_steps, message)

    async def set_progress(self, progress: float, message: Optional[str] = None):
        """设置进度百分比"""
        await self.tracker.set_progress(progress, message or "")

    async def add_step(self, step_name: str, message: str = ""):
        """添加完成步骤"""
        await self.tracker.add_step(step_name, message)

    async def complete(self, message: Optional[str] = None):
        """标记任务完成"""
        await self.tracker.complete(message or "任务完成")

    async def fail(self, error_message: str, details: Optional[dict] = None):
        """标记任务失败"""
        await self.tracker.fail(error_message, details)

    async def set_subtask_progress(
        self, subtask_name: str, progress: float, weight: float = 1.0
    ):
        """设置子任务进度"""
        await self.tracker.set_subtask_progress(subtask_name, progress, weight)

    @property
    def current_progress(self) -> dict:
        """获取当前进度快照"""
        return self.tracker.current_progress

    def add_callback(self, callback):
        """添加进度更新回调"""
        self.tracker.add_callback(callback)
